package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.SpuAddNewDTO;
import cn.tedu.csmall.product.service.SpuService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理SPU相关请求的控制器
 *
 * @author Chen
 * @since 2023/2/13 23:28:28
 */
@Slf4j
@RestController
@RequestMapping("/spu")
@Tag(name = "07. SPU管理模块")
public class SpuController {

    private final SpuService spuService;

    @Autowired
    public SpuController(SpuService spuService) {
        this.spuService = spuService;
    }

    // http://localhost:8088/spu/add-new
    @Operation(summary = "添加SPU")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(SpuAddNewDTO spuAddNewDTO) {
        log.debug("开始处理【添加SPU】的请求，参数：{}", spuAddNewDTO);
        spuService.addNew(spuAddNewDTO);
        log.debug("添加SPU成功！");
        return JsonResult.ok();
    }

}
